<template>
	<view class="page page-fill">
		<!-- 上面部分start -->
		<view class="page-block info-list">
			<!-- 头像 -->
			<view class="item-wrapper face-line-upbottom" @click="operator">
				<view class="info-words">头像</view>
				<view class="right-wrapper">
					<image :src="globalUser.faceImage" class="face" mode=""></image>
					<view class="arrow-block">
						<image  src="../../static/left-gray-arrow.png" class="arrow-image" mode=""></image>
					</view>
				</view>
			</view>
			<!-- //横线 -->
			<view class="line-wrapper1">
				<view class="line1"></view>
			</view>
			<!-- 昵称 -->
			<view class="item-wrapper" @click="modifyNickname">
				<view class="info-words">昵称</view>
				<view class="right-wrapper">
					<view class="gray-fields">{{globalUser.nickname}}</view>
					<view class="arrow-block">
						<image  src="../../static/left-gray-arrow.png" class="arrow-image" mode=""></image>
					</view>
				</view>
			</view>
			<!-- //横线 -->
			<view class="line-wrapper1">
				<view class="line1"></view>
			</view>
			<!-- 生日 -->
			<view class="item-wrapper">
				<view class="info-words">生日</view>
				<view class="right-wrapper">
				  <view class="gray-fields">{{globalUser.birthday}}</view>
					<view class="arrow-block">
						<image  src="../../static/left-gray-arrow.png" class="arrow-image" mode=""></image>
					</view>
				</view>
			</view>
			<!-- //横线 -->
			<view class="line-wrapper1">
				<view class="line1"></view>
			</view>
			<!-- 性别 -->
			<view class="item-wrapper">
				<view class="info-words">性别</view>
				<view class="right-wrapper">
					
					<view v-if="globalUser.sex==1" class="gray-fields">
						男
					</view>
					<view v-else-if="globalUser.sex==0" class="gray-fields">
						女
					</view>
					<view class="gray-fields">
						未选择
					</view>
					<view class="arrow-block">
						<image  src="../../static/left-gray-arrow.png" class="arrow-image" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 下面部分end -->
		
		<view class="footer-wrapper">
			<view class="footer-words" @click="clearStorage">
				清理缓存
			</view>
			<view class="footer-words" style="margin-top: 10upx;" @click="logout">
				退出登陆
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				globalUser:{}
			}
		},
		onShow(){
			var me=this;
			// globalUser 我的账号里面所有信息
			var globalUser=me.getGlobalUser("globalUser")
			me.globalUser=globalUser;
			console.log(me.globalUser);
		},
		methods: {
			//修改昵称
			modifyNickname(){
				uni.navigateTo({
					url:'../meNickname/meNickname'
				})
			},
			operator(){
				var me=this;
				var globalUser=me.getGlobalUser("globalUser")
				
				//从底部出来弹框效果
				uni.showActionSheet({
					itemList:["查看我的头像",'从相册选择上传'],
					success(res) {
						var index=res.tapIndex;
						console.log(res);
						if(index==0){
							//预览头像
							var faceArr=[];
							faceArr.push(globalUser.faceImage);
							uni.previewImage({
								urls:faceArr,
								current:faceArr[0]
							})
							
						}else if(index==1){
							//选择上传头像
							uni.chooseImage({
								count:1,
								sizeType:['compressed'],
								sourceType:['album'],
								success(res) {
									// 图片的本地文件路径列表,获得临时路径
								var tempFilePaths=res.tempFilePaths[0];
								//路由跳转
								uni.navigateTo({
									url:'../meface/meface?tempFilePaths='+tempFilePaths
								})
								}
							})
						}
					}
				})
			},
			
				clearStorage(){
					//清理本地数据缓存。
					uni.clearStorage();
					//成功对勾
					uni.showToast({
						title:"清理缓存成功",
						mask:false,
						duration:1500
					})
				},
				//用户退出登陆   
				logout(){
					var globalUser=this.getGlobalUser("globalUser");
					uni.request({
						url: 'https://www.imovietrailer.com/superhero/user/logout?userId='+globalUser.id+'&qq=lee57837906',
						
						method: 'POST',
						success: (res) => {
							// debugger
							if(res.data.status==200){
								//如果服务器返回200，代表用户在服务端退出登陆成功
								// 从本地缓存中同步移除指定 key。
								uni.removeStorageSync("globalUser");
								uni.switchTab({
									url:"../me/me"
								})
							}
							
						}
					});
				}
		}
		
	}
</script>

<style>
	@import url("meInfo.css");
</style>
